home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / T U R B O Language / Turbo C v2.0 / SETENVP.ASM < prev    next >
Assembly Source File  |  1988-08-29  |  2KB  |  118 lines

  1.     NAME    SETENVP
  2.     PAGE    60,132
  3. ;[]------------------------------------------------------------[]
  4. ;|    SETENVP.ASM -- Prepare Environment            |
  5. ;|                                |
  6. ;|    Turbo-C Run Time Library    version 2.0        |
  7. ;|                                |
  8. ;|    Copyright (c) 1988 by Borland International Inc.    |
  9. ;|    All Rights Reserved.                    |
  10. ;[]------------------------------------------------------------[]
  11.  
  12.     INCLUDE RULES.ASI
  13.  
  14. ;    Segment and Group declarations
  15.  
  16. Header@
  17.  
  18. ;    External references
  19.  
  20. ExtProc@    malloc, __CDECL__
  21. ExtProc@    abort, __CDECL__
  22.  
  23. ExtSym@        _envseg, WORD, __CDECL__
  24. ExtSym@        _envLng, WORD, __CDECL__
  25. ExtSym@        _envSize, WORD, __CDECL__
  26. dPtrExt@    environ, __CDECL__
  27.  
  28.     SUBTTL    Prepare Environment
  29.     PAGE
  30. ;/*                            */
  31. ;/*-----------------------------------------------------*/
  32. ;/*                            */
  33. ;/*    Prepare Environment                */
  34. ;/*    -------------------                */
  35. ;/*                            */
  36. ;/*-----------------------------------------------------*/
  37. ;/*                            */
  38.  
  39. CSeg@
  40.  
  41. PubProc@    _setenvp, __CDECL__
  42.  
  43. ;    Allocate a buffer to hold environment variables
  44.  
  45. IF    LDATA EQ 0
  46.         mov    cx, _envLng@
  47.         push    cx
  48.         call    malloc@
  49.         pop    cx
  50.         mov    di, ax
  51.         or    ax, ax
  52.         jz    _Failed        ; Memory allocation failed
  53.         push    ds
  54.         push    ds
  55.         pop    es
  56.         mov    ds, _envseg@
  57.         xor    si, si
  58.         cld
  59.         rep    movsb
  60.         pop    ds
  61.         mov    di, ax
  62. ELSE
  63.         mov    es, _envseg@
  64.         xor    di, di
  65. ENDIF
  66.  
  67. ;    Allocate a buffer to hold envp array
  68.  
  69.         push    es        ; Save Environment Segment address
  70.         push    _envSize@
  71.         call    malloc@
  72.         add    sp, 2
  73.         mov    bx, ax
  74.         pop    es        ; Restore Environment Segment address
  75. IF    LDATA
  76.         mov    word ptr environ@, ax
  77.         mov    word ptr environ@+2, dx
  78.         push    ds
  79.         mov    ds, dx
  80.         or    ax, dx
  81. ELSE
  82.         mov    word ptr environ@, ax
  83.         or    ax, ax
  84. ENDIF
  85.         jnz    SetEnviron    ; Memory allocation failed
  86. _Failed        label    near        ; Memory allocation failed
  87.         jmp    abort@
  88.  
  89.  
  90. ;    Now, store environment variables address
  91.  
  92. SetEnviron    label    near
  93.         xor    ax, ax
  94.         mov    cx, -1
  95. SetEnviron0    label    near
  96.         mov    [bx], di
  97. IF    LDATA
  98.         mov    [bx+2], es
  99.         add    bx, 4
  100. ELSE
  101.         add    bx, 2
  102. ENDIF
  103.         repnz    scasb
  104.         cmp    es:[di], al
  105.         jne    SetEnviron0    ; Set next pointer
  106. IF    LDATA
  107.         mov    [bx], ax
  108.         mov    [bx+2], ax
  109.         pop    ds
  110. ELSE
  111.         mov    [bx], ax
  112. ENDIF
  113.         ret
  114. EndProc@    _setenvp, __CDECL__
  115.  
  116. CsegEnd@
  117.     END
  118.